package com.mystudy.utils;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

/**
 * @program: infoalgorithm
 * @description: 过滤日志文件的类
 * @author: zhouzhilong
 * @create: 2020-08-04 10:00
 **/

public class FilterLogUtil {
    /** logger */
    private static final Logger LOGGER = LoggerFactory.getLogger(FilterLogUtil.class);
    @Test
    public void filterLog() throws IOException {
        String fileName = ("/home/wizarpos/Downloads/Compressed/WP19181Q20012190-20200803180054/main/logcat/logcat.txt.01");
        String outFileName = ("1.txt");
        String filter = "4243";
        File file = new File(fileName);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        BufferedWriter writer = new BufferedWriter(new FileWriter(outFileName));
        String data = null;
        while((data = reader.readLine()) != null){
            if(data.contains(filter)){
                writer.write(data+"\n");
            }
        }
        Integer[] arr = new Integer[1412];
        StringUtils.join(arr,",");

    }


    @Test
    public void testf(){
        double v = GetDistance(31.244719, 121.414123, 31.244719, 121.413670);
        LOGGER.debug("v = [{}]",v);
    }

    public  double GetDistance(double lng1, double lat1, double lng2, double lat2)
    {
        double radLat1 = rad(lat1);
        double radLat2 = rad(lat2);
        double a = radLat1 - radLat2;
        double b = rad(lng1) - rad(lng2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
                Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }

    private  final double EARTH_RADIUS = 6378137;
    private  double rad(double d)
    {
        return d * Math.PI / 180.0;
    }

}
